/*
 * ActivityChooser.java
 *
 * Created on March 26, 2007, 3:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Experience.Screens;

import Experience.*;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;

/**
 *
 * @author dmgreen
 */
public class GlucoseValueScreen extends Form implements CommandListener, ItemStateListener {
    
    TextField myGlucoseValueTF;
    int myGlucoseValue   = 0;
    
    ExpUI myMIDlet = null;
    
    /** Creates a new instance of ActivityChooser */
    public GlucoseValueScreen( MIDlet expsamp ) {
        super ("Glucose Value");
        
        myMIDlet = (ExpUI) expsamp;
        
        myGlucoseValueTF   = new TextField("" , "", 5, TextField.NUMERIC);
        
        this.append("Please enter your reference blood glucose value:");
        this.append(myGlucoseValueTF);
        
        this.setItemStateListener(this);
        
        this.addCommand(new Command("Next", Command.OK, 1));
        this.setCommandListener(this);
        
    }
 
    public void commandAction(Command com, Displayable dis) {
	String label = com.getLabel();
	
        if ("Next".equals(label)) {
            myMIDlet.notifyNext(String.valueOf(getGlucoseValue()));
        }
    }

    public void itemStateChanged(Item item) {
       if (item == myGlucoseValueTF) {
           try {
               myGlucoseValue = Integer.parseInt( ((TextField) item).getString() );
           } catch (NumberFormatException nfe) {
               myGlucoseValue = 0;
           }
       } 
    }
    
    public int getGlucoseValue() {
        return myGlucoseValue;
    }
}
